<!DOCTYPE html>
<html>

<head>
  <title>PDF - AIL</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">

  <!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/tags.css') }}" rel="stylesheet" type="text/css" />
    <link href="{{ url_for('static', filename='css/ail-project.css') }}" rel="stylesheet">

  <!-- JS -->
	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
    <script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap4.min.js') }}"></script>
	<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
    <script src="{{ url_for('static', filename='js/tags.js') }}"></script>

</head>
<body>

	{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">

			{% include 'sidebars/sidebar_objects.html' %}

			<div class="col-12 col-lg-10" id="core_content">

                {% with meta=meta, is_correlation=False %}
                    {% include 'objects/pdf/card_pdf.html' %}
                {% endwith %}

            </div>

        </div>
    </div>

<script>
    var chart = {};
    var to_refresh;
    var tasks_uuid = new Set();
    $(document).ready(function(){
        $("#page-Decoded").addClass("active");
        $("#nav_chat").addClass("active");

        {% if meta['translated'] %}
            {% if meta['translated']['task'] %}
            $( window ).on("focus", function() {
                to_refresh = true
                refresh_progress_status();
                progress_interval = setInterval(function(){
                    refresh_progress_status()
                }, 5000);
            });
            $( window ).on("blur", function() {
                to_refresh = false
            });
            to_refresh = true
            refresh_progress_status();
            {% endif %}
        {% endif %}

  });

function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}

{% if meta['translated'] %}
    {% if meta['translated']['task'] %}
    function refresh_progress_status(){

      $.getJSON("{{ url_for('objects_pdf.pdf_translated_progress', id=meta['id']) }}", function(data){
        if(! jQuery.isEmptyObject(data)){
            for (const [task_uuid, value] of Object.entries(data)) {
                let progress_id = "#tr_progress_" + task_uuid
                $(progress_id).attr('aria-valuenow', value).width(value+'%').text(value+'%');
                tasks_uuid.add(task_uuid)
            }

            for (const task_uuid of tasks_uuid) {
              if (!(task_uuid in data)) {
                  location.reload();
              }
            }
        } else {
          for (const task_uuid of tasks_uuid) {
              location.reload();
            }
          to_refresh = false
          clearInterval(progress_interval);
        }
      });

      if (! to_refresh) {
          to_refresh = false
          clearInterval(progress_interval);
      }

    }

    refresh_progress_status();
    //Interval
    var progress_interval = setInterval(function(){
        refresh_progress_status()
    }, 5000);
    {% endif %}
{% endif %}


</script>

</body>

</html>
